package com.java.job;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author
 * @date 2018/9/28 14:46
 */
public class MySimpleJob implements SimpleJob {

    public void execute(ShardingContext context) {
        //分片序列号
        int shardingItem = context.getShardingItem();
        //分片总数
        int totalCount = context.getShardingTotalCount();
        System.out.println("分片序列号：" + shardingItem);
        for (int i = 0; i < 10; i++) {
            if (i % totalCount == shardingItem) {
                String time = new SimpleDateFormat("HH:mm:ss").format(new Date());
                System.out.println(time + ":开始执行简单任务" + i);
            }
        }
    }
}
